home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / rexx / rkr_rexx.lzh / replace.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1995-01-15  |  529 b   |  27 lines

  1. /*
  2. **  Replace all occurances of an old substring with a new substring.  E.g.:
  3. **    x = 'foo.txt'
  4. **    x = 'rename' x replace( x, '.txt', '.text' )
  5. **    say x
  6. **        ==> rename foo.txt foo.text
  7. **
  8. **  NOTES:
  9. **    It _IS_ safe to do:
  10. **        say replace( 'abc', 'b', 'bb' )
  11. **        ==> abbc
  12. **
  13. **    I.e., it does not get caught in infinite loops.  (^&
  14. **
  15. */
  16. parse arg src, old, new
  17.     str = ''
  18.     do while '' ~= src
  19.     loc = pos( old, src )
  20.     parse var src sub (old) src
  21.     str = str || sub
  22.     if loc ~= 0 then
  23.         str = str || new
  24.     end
  25. return str
  26.  
  27.